﻿using System;
using System.Web.UI;

namespace ADEVSO.Web.UI
{
    public class GlobalizationMasterPage : MasterPage
    {
        protected virtual void Page_Load(object sender, EventArgs e)
        {
            ApplyCulture();
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Page.ClientScript.RegisterClientScriptResource(typeof(GlobalizationMasterPage), "ADEVSO.Web.Resources.culture.js");
        }

        public void ApplyCulture()
        {
            InitializeCulture();
            ApplyAdditionalCulture();
        }

        protected virtual void ApplyAdditionalCulture()
        {
        }

        protected void InitializeCulture()
        {
            try
            {
                //if (CurrentCulture != Session["CurrentCulture"].ToString())
                //    CurrentCulture = Session["CurrentCulture"].ToString();
            }
            catch
            {
                //throw;
            }
        }

        /// <summary>
        /// Page Current Culture
        /// </summary>
        public String CurrentCulture
        {
            get
            {
                return (Page as GlobalizationPage).CurrentCulture;
            }
            set
            {
                (Page as GlobalizationPage).CurrentCulture = value;
                //ApplyCulture();
            }
        }

        /// <summary>
        /// Setup include files, js and css files
        /// </summary>
        private void SetupIncludes()
        {
            ClientScriptManager cs = Page.ClientScript;
            String csName = "CultureScript";
            Type csType = this.GetType();

            if (!cs.IsStartupScriptRegistered(csType, csName))
            {
                // Register dummy startup script so that this is only added for the first control
                cs.RegisterStartupScript(csType, csName, "", true);

                // Register Javascript Resource
                cs.RegisterClientScriptInclude(
                   csType, "cs",
                   Page.ClientScript.GetWebResourceUrl(csType,
                   "Bright.WebControls.Resources.ThumbViewer.js"));

                //// Add the style sheet to the document header
                //String csslink = "\n<link href='" +
                //   Page.ClientScript.GetWebResourceUrl(csType,
                //   "Bright.WebControls.Resources.ThumbViewer.css")
                //   + "' rel='stylesheet' type='text/css' />";

                //LiteralControl include = new LiteralControl(csslink);
                //this.Page.Header.Controls.Add(include);
            }
        }
    }
}